import React, {Component} from 'react';
import './index.less'
import OrderBy from "./OrderBy";
import AllSideGoods from "./AllSideGoods";
import {getBrandGoods,getBrandGoodsPriceUp,getBrandGoodsDown} from "../../network/goods";

class GoodsList extends Component {
    state = {
        Brand: 1,
        data: [],
        order: 1
    }
    render() {
        return (
            <div className='applePage'>
                <div className="container">
                    <OrderBy getOrder={this.getOrder}/>
                    <AllSideGoods data={this.state.data}/>
                </div>
            </div>

        );
    }
    componentDidMount() {
        this.getOrder(this.state.order)
    }
    getOrder = (flag) => {
        this.setState({
            order: flag*1
        },async () => {
            const {order} = this.state
            let result;
            if(order === 1){
                result = await getBrandGoods(this.props.gid)
            }
            if(order === 2){
                result = await getBrandGoodsDown(this.props.gid)
            }
            if(order === 3){
                result = await getBrandGoodsPriceUp(this.props.gid)
            }
            if(result.code === 200){
                this.setState({
                    data: result.data
                })
            }
        })
    }
}

export default GoodsList;